﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WorkNodeFramework
{
    public enum OrderByEnum
    {
        ASC,DESC
    }

    internal interface IOrderBy {
        string Expression { get; }
        OrderByEnum OrderBy { get; set; }
    }

    internal class ColumnOrderBy : IOrderBy
    {
        Column col;
        OrderByEnum orderBy = OrderByEnum.ASC;

        internal ColumnOrderBy(Column col, OrderByEnum orderBy)
        {
            this.col = col;
            this.orderBy = orderBy;
        }

        internal Column Column {
            get {
                return col;
            }
        }

        public OrderByEnum OrderBy {
            get {
                return orderBy;
            }
            set {
                orderBy = value;
            }
        }

        public string Expression {
            get { 
                string order = orderBy==OrderByEnum.ASC?"ASC":"DESC";
                return col.FullName + " " + order;
            }
        }
    }

    internal class ColumnNameOrderBy : IOrderBy
    {
        string colName;
        OrderByEnum orderBy = OrderByEnum.ASC;

        internal ColumnNameOrderBy(string columnName, OrderByEnum orderBy)
        {
            this.colName = columnName;
            this.orderBy = orderBy;
        }

        internal string ColumnName {
            get {
                return colName;
            }
        }

        public OrderByEnum OrderBy {
            get {
                return orderBy;
            }
            set {
                orderBy = value;
            }
        }
        #region IOrderBy Members

        public string Expression
        {
            get
            {
                string order = orderBy == OrderByEnum.ASC ? "ASC" : "DESC";
                return colName + " " + order;
            }
        }

        #endregion
    }

}
